import { createBrowserRouter } from 'react-router-dom';
import App from '../App';
import UserList from '../pages/rbac/UserList'
import RoleList from '../pages/rbac/RoleList';
import MenuList from '../pages/rbac/MenuList';
import Login from '../pages/Login';
import RequireAuth from './RequireAuth';
import Register from '../pages/Register';
// 项目路由
// 一级路由组件
import Workbench from '../pages/WorkBench';                // 工作台页面
import EmployeePerformance from '../pages/EmployeePerformance'; // 员工绩效管理页面
import SubcontractSuppliers from '../pages/SubcontractSuppliers'; // 分包供应商管理页面
import ProjectMessages from '../pages/ProjectMessages';      // 项目消息页面
import ProjectList from '../pages/project/ProjectList';      // 项目列表页面
import NewProject from '../pages/project/NewProject';        // 新建项目页面
import NewProjectPhase from '../pages/project/NewProjectPhase'; // 新增项目阶段页面
import Profile from '../pages/Profile';       // 个人信息页面

// 二级路由组件（项目详情下的子路由）
import ProjectDetail from '../pages/project/detail/ProjectDetail';       // 项目详情页面
import AfterSalesDemand from '../pages/project/detail/AfterSalesDemand'; // 售后需求记录页面
import AfterSalesList from '../pages/project/detail/AfterSalesList';     // 售后需求列表页面
import ProjectCorrespondence from '../pages/project/detail/ProjectCorrespondence'; // 项目函件列表页面
import ProjectPhaseList from '../pages/project/detail/ProjectPhaseList'; // 项目阶段列表页面
import ProjectTaskList from '../pages/project/detail/ProjectTaskList';   // 项目任务列表页面
// import ProjectAttachments from '../pages/project/detail/ProjectAttachments'; // 项目附件页面（暂未启用）
import ProjectMeetingNotes from '../pages/project/detail/ProjectMeetingNotes'; // 项目会议纪要页面
import ProjectBonusRecords from '../pages/project/detail/ProjectBonusRecords'; // 项目奖金记录页面
import ProjectSettings from '../pages/project/detail/ProjectSettings';         // 项目信息配置页面

const router = createBrowserRouter([
  {
    path: '/',
    element: (
      <RequireAuth>
        <App />
      </RequireAuth>
    )
    , // 根路径，加载App组件
    children: [
      {
        path: 'work',
        element: <Workbench /> // 工作台
      },
      {
        path: 'dashboard',
        children: [
          {
            path: 'userlist',
            element: <UserList /> // 用户列表
          },
          {
            path: 'rolelist',
            element: <RoleList /> // 角色列表
          },
          {
            path: 'menulist',
            element: <MenuList /> // 菜单列表
          }
        ]
      },
      {
        path: 'performance',
        element: <EmployeePerformance /> // 员工绩效管理
      },
      {
        path: 'suppliers',
        element: <SubcontractSuppliers /> // 分包供应商
      },
      {
        path: 'messages',
        element: <ProjectMessages /> // 消息-项目消息
      },
      {
        path: 'projects', // 项目管理
        children: [
          {
            path: 'projectlist',
            element: <ProjectList /> // 项目列表
          },
          {
            path: 'projectId',
            element: <ProjectDetail />, // 项目详情

          },

          {
            path: 'aftersales',
            element: <AfterSalesDemand /> // 售后需求记录
          },
          {
            path: 'aftersaleslist',
            element: <AfterSalesList /> // 售后需求列表
          },
          {
            path: 'correspondence',
            element: <ProjectCorrespondence /> // 项目函件列表
          },
          {
            path: 'phases',
            element: <ProjectPhaseList /> // 项目阶段列表
          },
          {
            path: 'tasks',
            element: <ProjectTaskList /> // 项目任务列表
          },
          {
            path: 'meetingnotes',
            element: <ProjectMeetingNotes /> // 项目会议记要
          },
          {
            path: 'bonusrecords',
            element: <ProjectBonusRecords /> // 项目奖金记录
          }

        ]
      },
      {
        path: 'system',
        children: [
          {
            path: 'settings',
            element: <ProjectSettings /> // 项目信息配置
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    element: <Login /> // 登录页面
  },
  {
    path: '/profile',
    element: <Profile />
  },
  {
    path: 'newproject',
    element: (
      <RequireAuth>
        <NewProject />
      </RequireAuth>
    )
  },
  {
    path: 'newphase',
    element: (
      <RequireAuth>
        <NewProjectPhase />
      </RequireAuth>
    )
  },
  {
    path: '/register',
    element: <Register /> // 注册页面
  },
]);

export default router;